<?php
class ProductInfoModel extends Eloquent{
    protected $table = 'product_info';
    protected $appends = array(
        //'author',
        //'extra',
        'image_url',
    );
    protected $hidden = array('field','image');
    public function getAuthorAttribute(){
        foreach($this->field as &$v){
            if($v['name'] = 'author')
                return $v['value_string'];
        }
    }
    public function field(){
        return $this->hasMany('ProductFieldModel','product_id','product_id');
    }
    public function getExtraAttribute(){
        $data = array();
        foreach($this->field as &$v){
            $data[$v['name']] = $v['value_'.$v['type']];
        }
        return $data;
    }
    public function getImageUrlAttribute($value){
        $value = $this->image;
        if(empty($value)) return '';
        $baseUrl = '';
        return $baseUrl.$value;
    }
}

